﻿using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.DataSourcesRaster;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.GeoAnalyst;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.SpatialAnalyst;
using ESRI.ArcGIS.SystemUI;
using stdole;
using Swsk33.SimpleArcEngine.Dialog;
using Swsk33.SimpleArcEngine.Util;
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace Swsk33.SimpleArcEngine
{
	public partial class MainGUI : Form
	{
		public MainGUI()
		{
			InitializeComponent();
			// 实例化时同步鹰眼数据
			SyncMapAndHawkeye();
		}

		/// <summary>
		/// 同步鹰眼和主地图数据
		/// </summary>
		public void SyncMapAndHawkeye()
		{
			hawkeye.Map.ClearLayers();
			for (int i = 0; i < mainMapControl.Map.LayerCount; i++)
			{
				hawkeye.Map.AddLayer(mainMapControl.Map.get_Layer(i));
			}
			// 设置鹰眼视图为全局视图
			hawkeye.Extent = mainMapControl.FullExtent;
			hawkeye.Refresh();
		}

		/// <summary>
		/// 按钮-添加数据
		/// </summary>
		private void addDataButton_Click(object sender, EventArgs e)
		{
			ICommand cmd = new ControlsAddDataCommand();
			cmd.OnCreate(mainMapControl.Object);
			cmd.OnClick();
			// 每次添加数据，鹰眼和主图同步
			SyncMapAndHawkeye();
		}

		/// <summary>
		/// 按钮-放大
		/// </summary>
		private void zoomInButton_Click(object sender, EventArgs e)
		{
			ICommand cmd = new ControlsMapZoomInTool();
			cmd.OnCreate(mainMapControl.Object);
			mainMapControl.CurrentTool = (ITool)cmd;
		}

		/// <summary>
		/// 按钮-缩小
		/// </summary>
		private void zoomOutButton_Click(object sender, EventArgs e)
		{
			ICommand cmd = new ControlsMapZoomOutTool();
			cmd.OnCreate(mainMapControl.Object);
			mainMapControl.CurrentTool = (ITool)cmd;
		}

		/// <summary>
		/// 按钮-移动地图
		/// </summary>
		private void mapPanButton_Click(object sender, EventArgs e)
		{
			ICommand cmd = new ControlsMapPanTool();
			cmd.OnCreate(mainMapControl.Object);
			mainMapControl.CurrentTool = (ITool)cmd;
		}

		/// <summary>
		/// 按钮-量测
		/// </summary>
		private void measureButton_Click(object sender, EventArgs e)
		{
			ICommand cmd = new ControlsMapMeasureTool();
			cmd.OnCreate(mainMapControl.Object);
			mainMapControl.CurrentTool = (ITool)cmd;
		}

		/// <summary>
		/// 按钮-辨识
		/// </summary>
		private void indentifyButton_Click(object sender, EventArgs e)
		{
			ICommand cmd = new ControlsMapIdentifyTool();
			cmd.OnCreate(mainMapControl.Object);
			mainMapControl.CurrentTool = (ITool)cmd;
		}

		/// <summary>
		/// 按钮-换回鼠标
		/// </summary>
		private void cursor_Click(object sender, EventArgs e)
		{
			mainMapControl.CurrentTool = null;
		}

		/// <summary>
		/// 切换主视图Map或者Layout
		/// </summary>
		private void mapTabCotrol_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (mapTabCotrol.SelectedIndex == 1)
			{
				IObjectCopy objectCopy = new ObjectCopy();
				var originMap = mainMapControl.ActiveView.FocusMap;
				object copyMap = objectCopy.Copy(originMap);
				object overwriteMap = mainPageLayoutControl.ActiveView.FocusMap;
				objectCopy.Overwrite(copyMap, overwriteMap);
				mainTocControl.SetBuddyControl(mainPageLayoutControl.Object);
				mainPageLayoutControl.Refresh();
			}
			else
			{
				mainTocControl.SetBuddyControl(mainMapControl.Object);
			}
		}

		/// <summary>
		/// 按钮-删除图层窗口
		/// </summary>
		private void manageButton_Click(object sender, EventArgs e)
		{
			ManageDialog manageDialog = new ManageDialog(mainMapControl);
			for (int i = 0; i < mainMapControl.LayerCount; i++)
			{
				manageDialog.layerNames.Items.Add(mainMapControl.get_Layer(i).Name);
			}
			manageDialog.ShowDialog();
			// 同步鹰眼
			SyncMapAndHawkeye();
		}

		/// <summary>
		/// 在鹰眼上绘制红色方框
		/// </summary>
		private void mainMapControl_OnAfterScreenDraw(object sender, IMapControlEvents2_OnAfterScreenDrawEvent e)
		{
			if (mainMapControl.LayerCount == 0)
			{
				return;
			}
			// 得到新范围
			IEnvelope mainMapExtent = mainMapControl.Extent;
			// 获取鹰眼地图
			IGraphicsContainer hawkeyeContainer = (IGraphicsContainer)hawkeye.Map;
			IActiveView hawkeyeActiveView = (IActiveView)hawkeyeContainer;
			// 在绘制前，清除鹰眼中的任何图形元素
			hawkeyeContainer.DeleteAllElements();
			IRectangleElement pRectangleEle = new RectangleElementClass();
			IElement pEle = (IElement)pRectangleEle;
			pEle.Geometry = mainMapExtent;
			// 设置鹰眼图中的红线框
			IRgbColor color = new RgbColorClass();
			color.Red = 255;
			color.Green = 0;
			color.Blue = 0;
			color.Transparency = 255;
			// 产生一个线符号对象
			ILineSymbol outline = new SimpleLineSymbolClass();
			outline.Width = 2;
			outline.Color = color;
			// 设置颜色属性
			color = new RgbColorClass();
			color.Red = 255;
			color.Green = 0;
			color.Blue = 0;
			color.Transparency = 0;
			// 设置填充符号的属性
			IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
			pFillSymbol.Color = color;
			pFillSymbol.Outline = outline;
			IFillShapeElement pFillShapeEle = (IFillShapeElement)pEle;
			pFillShapeEle.Symbol = pFillSymbol;
			hawkeyeContainer.AddElement((IElement)pFillShapeEle, 0);
			// 刷新
			hawkeyeActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
		}

		/// <summary>
		/// 禁止鹰眼缩放
		/// </summary>
		private void hawkeye_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e)
		{
			// 设置鹰眼视图为全局视图
			hawkeye.Extent = mainMapControl.FullExtent;
			hawkeye.Refresh();
		}

		/// <summary>
		/// 鹰眼上的点击事件
		/// </summary>
		private void hawkeye_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
		{
			if (hawkeye.Map.LayerCount > 0)
			{
				// 左键将所点击的位置，设置为主视图的中心
				if (e.button == 1)
				{
					IPoint pPoint = new PointClass();
					// 设置point对象的坐标
					pPoint.PutCoords(e.mapX, e.mapY);
					mainMapControl.CenterAt(pPoint);
					mainMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
				}
				// 右键拉框范围设置为主视图显示范围
				else if (e.button == 2)
				{
					// 获得拉框的范围
					IEnvelope pEnv = hawkeye.TrackRectangle();
					mainMapControl.Extent = pEnv;
					mainMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
				}
			}
		}

		/// <summary>
		/// 鹰眼上鼠标移动变化视图范围
		/// </summary>
		private void hawkeye_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
		{
			if (e.button == 1)
			{
				// 左键点击移动，俩个视图联动
				IPoint pPoint = new PointClass();
				pPoint.PutCoords(e.mapX, e.mapY);
				mainMapControl.CenterAt(pPoint);
				mainMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
			}
		}

		/// <summary>
		/// 在地图上标点
		/// </summary>
		private void markerToolStripMenuItem_Click(object sender, EventArgs e)
		{
			DrawElement drawElement = new DrawElement(Param.ElementType.POINT);
			drawElement.OnCreate(mainMapControl);
			mainMapControl.CurrentTool = drawElement;
		}

		/// <summary>
		/// 在地图上划线
		/// </summary>
		private void lineToolStripMenuItem_Click(object sender, EventArgs e)
		{
			DrawElement drawElement = new DrawElement(Param.ElementType.LINE);
			drawElement.OnCreate(mainMapControl);
			mainMapControl.CurrentTool = drawElement;
		}

		/// <summary>
		/// 在地图上画多边形
		/// </summary>
		private void polygonToolStripMenuItem_Click(object sender, EventArgs e)
		{
			DrawElement drawElement = new DrawElement(Param.ElementType.POLYGON);
			drawElement.OnCreate(mainMapControl);
			mainMapControl.CurrentTool = drawElement;
		}

		/// <summary>
		/// 在地图上写字
		/// </summary>
		private void textToolStripMenuItem_Click(object sender, EventArgs e)
		{
			DrawElement drawElement = new DrawElement(Param.ElementType.TEXT);
			drawElement.OnCreate(mainMapControl);
			mainMapControl.CurrentTool = drawElement;
		}

		/// <summary>
		/// 在地图上绘制图片
		/// </summary>
		private void imageToolStripMenuItem_Click(object sender, EventArgs e)
		{
			DrawElement drawElement = new DrawElement(Param.ElementType.IMAGE);
			drawElement.OnCreate(mainMapControl);
			mainMapControl.CurrentTool = drawElement;
		}

		/// <summary>
		/// 清除所有绘画元素
		/// </summary>
		private void clearAToolStripMenuItem_Click(object sender, EventArgs e)
		{
			mainMapControl.ActiveView.GraphicsContainer.DeleteAllElements();
			mainMapControl.Refresh();
		}

		/// <summary>
		/// 查询面积大于5000的国家按钮
		/// </summary>
		private void queryAreaButton_Click(object sender, EventArgs e)
		{
			new QueryAreaDialog().ShowQueryResult(mainMapControl);
		}

		/// <summary>
		/// 框选查询按钮
		/// </summary>
		private void selectQueryButton_Click(object sender, EventArgs e)
		{
			SelectQueryFeature selectQueryFeature = new SelectQueryFeature();
			selectQueryFeature.OnCreate(mainMapControl);
			mainMapControl.CurrentTool = selectQueryFeature;
		}

		/// <summary>
		/// 打开ShapeFile文件
		/// </summary>
		private void openShapeFileButton_Click(object sender, EventArgs e)
		{
			IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
			FolderBrowserDialog dialog = new FolderBrowserDialog();
			dialog.Description = "请选择ShapeFile所在的目录";
			if (dialog.ShowDialog() == DialogResult.OK)
			{
				IWorkspace workspace = workspaceFactory.OpenFromFile(dialog.SelectedPath, 0);
				List<string> names = new List<string>();
				// 创建枚举型数据集对象，获取工作区中要素类文件
				IEnumDataset enumDataSet = workspace.get_Datasets(esriDatasetType.esriDTFeatureClass);
				IDataset dataSet;
				while ((dataSet = enumDataSet.Next()) != null)
				{
					names.Add(dataSet.Name);
				}
				string getShape = new OpenDatasetDialog().OpenShapeFileDialog(names);
				if (getShape.Equals(""))
				{
					return;
				}
				IFeatureClass featureClass = ((IFeatureWorkspace)workspace).OpenFeatureClass(getShape);
				IFeatureLayer featureLayer = new FeatureLayer();
				featureLayer.FeatureClass = featureClass;
				mainMapControl.AddLayer(featureLayer);
				// 同步鹰眼数据
				SyncMapAndHawkeye();
			}
		}

		/// <summary>
		/// 打开File GDB中的名为country要素类
		/// </summary>
		private void openFileGDBButton_Click(object sender, EventArgs e)
		{
			IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactory();
			FolderBrowserDialog dialog = new FolderBrowserDialog();
			dialog.Description = "请选择gdb的目录";
			if (dialog.ShowDialog() == DialogResult.OK)
			{
				IWorkspace workspace = workspaceFactory.OpenFromFile(dialog.SelectedPath, 0);
				// 打开其中的country要素类
				IFeatureClass featureClass = ((IFeatureWorkspace)workspace).OpenFeatureClass("country");
				IFeatureLayer featureLayer = new FeatureLayer();
				featureLayer.FeatureClass = featureClass;
				mainMapControl.AddLayer(featureLayer);
				// 同步鹰眼数据
				SyncMapAndHawkeye();
			}
		}

		/// <summary>
		/// 打开Personal GDB中的名为country要素类
		/// </summary>
		private void OpenPersonalGDBButton_Click(object sender, EventArgs e)
		{
			IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactory();
			OpenFileDialog dialog = new OpenFileDialog();
			dialog.Filter = "Access Database文件|*.mdb";
			if (dialog.ShowDialog() == DialogResult.OK)
			{
				IWorkspace workspace = workspaceFactory.OpenFromFile(dialog.FileName, 0);
				IFeatureClass featureClass = ((IFeatureWorkspace)workspace).OpenFeatureClass("country");
				IFeatureLayer featureLayer = new FeatureLayer();
				featureLayer.FeatureClass = featureClass;
				mainMapControl.AddLayer(featureLayer);
				// 同步鹰眼数据
				SyncMapAndHawkeye();
			}
		}

		/// <summary>
		/// 打开栅格数据
		/// </summary>
		private void openRasterButton_Click(object sender, EventArgs e)
		{
			IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactory();
			OpenFileDialog dialog = new OpenFileDialog();
			dialog.Filter = "所有文件|*.*";
			if (dialog.ShowDialog() == DialogResult.OK)
			{
				string filePath = dialog.FileName;
				IWorkspace workspace = workspaceFactory.OpenFromFile(filePath.Substring(0, filePath.LastIndexOf("\\")), 0);
				IRasterDataset dataSet = ((IRasterWorkspace)workspace).OpenRasterDataset(filePath.Substring(filePath.LastIndexOf("\\") + 1));
				IRasterLayer layer = new RasterLayer();
				layer.CreateFromDataset(dataSet);
				mainMapControl.AddLayer(layer);
				// 同步鹰眼数据
				SyncMapAndHawkeye();
			}
		}

		/// <summary>
		/// 重置视图缩放
		/// </summary>
		private void resetView_Click(object sender, EventArgs e)
		{
			mainMapControl.Extent = mainMapControl.FullExtent;
		}

		/// <summary>
		/// 点选删除元素
		/// </summary>
		private void clickDeleteMenuItem_Click(object sender, EventArgs e)
		{
			DeleteElement deleteElement = new DeleteElement();
			deleteElement.OnCreate(mainMapControl);
			mainMapControl.CurrentTool = deleteElement;
		}

		/// <summary>
		/// 合并指定字段值相同的要素
		/// </summary>
		private void mergeButton_Click(object sender, EventArgs e)
		{
			new MergeSameDialog(mainMapControl).ShowMergeDialog();
		}

		/// <summary>
		/// 打开点要素并赋予图片样式
		/// </summary>
		private void openPointShapeAsStar_Click(object sender, EventArgs e)
		{
			IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
			FolderBrowserDialog dialog = new FolderBrowserDialog();
			dialog.Description = "请选择ShapeFile所在的目录";
			if (dialog.ShowDialog() == DialogResult.OK)
			{
				IWorkspace workspace = workspaceFactory.OpenFromFile(dialog.SelectedPath, 0);
				List<string> names = new List<string>();
				// 创建枚举型数据集对象，获取工作区中要素类文件
				IEnumDataset enumDataSet = workspace.get_Datasets(esriDatasetType.esriDTFeatureClass);
				IDataset dataSet;
				while ((dataSet = enumDataSet.Next()) != null)
				{
					names.Add(dataSet.Name);
				}
				string getShape = new OpenDatasetDialog().OpenShapeFileDialog(names);
				if (getShape.Equals(""))
				{
					return;
				}
				IFeatureClass featureClass = ((IFeatureWorkspace)workspace).OpenFeatureClass(getShape);
				IFeatureLayer featureLayer = new FeatureLayer();
				featureLayer.FeatureClass = featureClass;
				// 创建符号
				string imagePath = new ImageDialog().ShowImageDialog();
				if (imagePath.Equals(""))
				{
					return;
				}
				var imageMarkType = esriIPictureType.esriIPictureJPG;
				if (imagePath.EndsWith("jpg", StringComparison.OrdinalIgnoreCase))
				{
					imageMarkType = esriIPictureType.esriIPictureJPG;
				}
				else if (imagePath.EndsWith("bmp", StringComparison.OrdinalIgnoreCase))
				{
					imageMarkType = esriIPictureType.esriIPictureBitmap;
				}
				else if (imagePath.EndsWith("png", StringComparison.OrdinalIgnoreCase))
				{
					imageMarkType = esriIPictureType.esriIPicturePNG;
				}
				else if (imagePath.EndsWith("gif", StringComparison.OrdinalIgnoreCase))
				{
					imageMarkType = esriIPictureType.esriIPictureGIF;
				}
				IPictureMarkerSymbol pictureMarker = new PictureMarkerSymbol();
				pictureMarker.CreateMarkerSymbolFromFile(imageMarkType, imagePath);
				pictureMarker.Size = 13;
				// 设定符号
				IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)featureLayer;
				IFeatureRenderer renderer = geoFeatureLayer.Renderer;
				ISimpleRenderer simpleRender = (ISimpleRenderer)renderer;
				simpleRender.Symbol = (ISymbol)pictureMarker;
				featureLayer.Name = getShape;
				mainMapControl.AddLayer(featureLayer);
				mainMapControl.Refresh();
				// 同步鹰眼数据
				SyncMapAndHawkeye();
			}
		}

		/// <summary>
		/// 将国家名以C开头的改变样式
		/// </summary>
		private void changePolygonSymbol_Click(object sender, EventArgs e)
		{
			IFeatureLayer countryFeatureLayer = null;
			// 获取国家图层
			for (int i = 0; i < mainMapControl.LayerCount; i++)
			{
				countryFeatureLayer = (IFeatureLayer)mainMapControl.get_Layer(i);
				if (countryFeatureLayer.Name == "country")
				{
					break;
				}
			}
			// 字段及其索引
			string fieldName = "CNTRY_NAME";
			int fieldIndex = countryFeatureLayer.FeatureClass.FindField(fieldName);
			IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)countryFeatureLayer;
			IUniqueValueRenderer uniqueRenderer = new UniqueValueRendererClass();
			uniqueRenderer.FieldCount = 1;
			uniqueRenderer.Field[0] = fieldName;
			// 创建默认符号样式
			ISimpleFillSymbol defaultSymbol = new SimpleFillSymbol();
			IRgbColor defaultColor = new RgbColor();
			defaultColor.Red = 201;
			defaultColor.Green = 242;
			defaultColor.Blue = 208;
			defaultSymbol.Color = defaultColor;
			uniqueRenderer.DefaultSymbol = (ISymbol)defaultSymbol;
			uniqueRenderer.UseDefaultSymbol = true;
			// 创建标识符号样式
			ISimpleFillSymbol fillSymbol = new SimpleFillSymbol();
			IRgbColor color = new RgbColor();
			color.Red = 254;
			color.Green = 201;
			color.Blue = 217;
			fillSymbol.Color = color;
			// 查询器
			IQueryFilter queryFilter = new QueryFilter();
			queryFilter.SubFields = "*";
			queryFilter.WhereClause = "\"CNTRY_NAME\" like \'C%\'";
			IFeatureCursor cursor = countryFeatureLayer.Search(queryFilter, false);
			IFeature feature;
			while ((feature = cursor.NextFeature()) != null)
			{
				uniqueRenderer.AddValue(feature.Value[fieldIndex].ToString(), feature.Value[fieldIndex].ToString(), (ISymbol)fillSymbol);
			}
			geoFeatureLayer.Renderer = (IFeatureRenderer)uniqueRenderer;
			mainMapControl.Refresh();
			SyncMapAndHawkeye();
		}

		/// <summary>
		/// 获取和绘制多边形相交的要素及其面积
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void getIntersectSquareButton_Click(object sender, EventArgs e)
		{
			SelectGetSquare selectGetSquare = new SelectGetSquare();
			selectGetSquare.OnCreate(mainMapControl);
			mainMapControl.CurrentTool = selectGetSquare;
		}

		/// <summary>
		/// 获取点击缓冲区内点
		/// </summary>
		private void pointBufferButton_Click(object sender, EventArgs e)
		{
			PointBufferQuery pointBufferQuery = new PointBufferQuery();
			pointBufferQuery.OnCreate(mainMapControl);
			mainMapControl.CurrentTool = pointBufferQuery;
		}

		/// <summary>
		/// 显示指定图层字段值在地图上
		/// </summary>
		private void showTextLabelButton_Click(object sender, EventArgs e)
		{
			if (mainMapControl.LayerCount <= 0)
			{
				MessageBox.Show("请至少加入一个图层！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
				return;
			}
			new TextMarkDialog(mainMapControl).ShowDialog();
		}

		/// <summary>
		/// 获取点击缓冲区内城市信息
		/// </summary>
		private void cityTreeViewButton_Click(object sender, EventArgs e)
		{
			GetCityInBuffer getCityInBuffer = new GetCityInBuffer();
			getCityInBuffer.OnCreate(mainMapControl);
			mainMapControl.CurrentTool = getCityInBuffer;
		}

		/// <summary>
		/// IDW插值
		/// </summary>
		private void rasterHandleButton_Click(object sender, EventArgs e)
		{
			if (mainMapControl.LayerCount == 0)
			{
				MessageBox.Show("请至少加入一个图层！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
				return;
			}
			IDWDialog dialog = new IDWDialog(mainMapControl);
			if (dialog.ShowDialog() == DialogResult.OK)
			{
				IFeatureClass featureClass = dialog.FeatureLayer.FeatureClass;
				// 创建要素类描述符，设定输入图层和字段
				IFeatureClassDescriptor descriptor = new FeatureClassDescriptorClass();
				descriptor.Create(featureClass, null, dialog.Field);
				IGeoDataset inputDataset = (IGeoDataset)descriptor;
				// 设定搜索半径
				IRasterRadius radius = new RasterRadius();
				radius.SetVariable(12);
				// 栅格分析器
				IInterpolationOp interpolationOp = new RasterInterpolationOpClass();
				IRasterAnalysisEnvironment rasterAnalysis = (IRasterAnalysisEnvironment)interpolationOp;
				// 设定格距
				rasterAnalysis.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, 0.5);
				// 创建工作区设定输出路径
				IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactory();
				rasterAnalysis.OutWorkspace = workspaceFactory.OpenFromFile(dialog.OutputPathString, 0);
				// 执行IDW插值
				IGeoDataset outputDataset = interpolationOp.IDW(inputDataset, 2, radius);
				// 得到插值
				IRasterLayer rasterLayer = new RasterLayer();
				rasterLayer.Name = dialog.FeatureLayer.Name + "_IDW";
				rasterLayer.CreateFromRaster((IRaster)outputDataset);
				mainMapControl.AddLayer(rasterLayer);
			}
		}

		/// <summary>
		/// 加入cities图层并用diamond符号显示
		/// </summary>
		private void addCitiesItem_Click(object sender, EventArgs e)
		{
			// 创建符号
			ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol();
			simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond;
			IRgbColor color = new RgbColor();
			color.Red = 0;
			color.Green = 0;
			color.Blue = 255;
			simpleMarkerSymbol.Color = color;
			simpleMarkerSymbol.Size = 5;
			// 使用工作区打开文件
			IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
			IWorkspace workspace = workspaceFactory.OpenFromFile(@"..\..\Resources\data", 0);
			IFeatureClass citiesFeatureClass = ((IFeatureWorkspace)workspace).OpenFeatureClass("cities");
			IFeatureLayer featureLayer = new FeatureLayer();
			featureLayer.FeatureClass = citiesFeatureClass;
			// 设定符号
			IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)featureLayer;
			// 获取图层的渲染器然后设定其符号即可
			ISimpleRenderer simpleRender = (ISimpleRenderer)geoFeatureLayer.Renderer;
			simpleRender.Symbol = (ISymbol)simpleMarkerSymbol;
			// 加入地图
			featureLayer.Name = "cities_diamond";
			mainMapControl.AddLayer(featureLayer);
			mainMapControl.Refresh();
			// 同步鹰眼数据
			SyncMapAndHawkeye();

		}

		/// <summary>
		/// 加入cities图层并用文字符号显示
		/// </summary>
		private void addCitiesShowTextSymbolItem_Click(object sender, EventArgs e)
		{
			// 创建符号
			ICharacterMarkerSymbol charMarkerSymbol = new CharacterMarkerSymbol();
			// 创建字体
			IFontDisp stdFont = (IFontDisp)new StdFont();
			stdFont.Name = "ESRI Default Marker";
			// 创建颜色
			IRgbColor color = new RgbColor();
			color.Red = 0;
			color.Green = 0;
			color.Blue = 255;
			// 设定字体和颜色等等
			charMarkerSymbol.Font = stdFont;
			charMarkerSymbol.CharacterIndex = 109;
			charMarkerSymbol.Color = color;
			charMarkerSymbol.Size = 20;
			// 使用工作区打开文件
			IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
			IWorkspace workspace = workspaceFactory.OpenFromFile(@"..\..\Resources\data", 0);
			IFeatureClass citiesFeatureClass = ((IFeatureWorkspace)workspace).OpenFeatureClass("cities");
			IFeatureLayer featureLayer = new FeatureLayer();
			featureLayer.FeatureClass = citiesFeatureClass;
			// 设定符号
			IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)featureLayer;
			// 获取图层的渲染器然后设定其符号即可
			ISimpleRenderer simpleRender = (ISimpleRenderer)geoFeatureLayer.Renderer;
			simpleRender.Symbol = (ISymbol)charMarkerSymbol;
			// 加入地图
			featureLayer.Name = "cities_char";
			mainMapControl.AddLayer(featureLayer);
			mainMapControl.Refresh();
			// 同步鹰眼数据
			SyncMapAndHawkeye();
		}

		/// <summary>
		/// 加入country图层并填充为蓝色
		/// </summary>
		private void addWorldAndFillColorItem_Click(object sender, EventArgs e)
		{
			// 创建符号
			ISimpleFillSymbol fillSymbol = new SimpleFillSymbol();
			// 创建颜色
			IRgbColor color = new RgbColor();
			color.Red = 212;
			color.Green = 232;
			color.Blue = 243;
			// 设定符号颜色及样式
			fillSymbol.Color = color;
			fillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
			// 使用工作区打开文件
			IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
			IWorkspace workspace = workspaceFactory.OpenFromFile(@"..\..\Resources\data", 0);
			IFeatureClass worldFeatureClass = ((IFeatureWorkspace)workspace).OpenFeatureClass("country");
			IFeatureLayer featureLayer = new FeatureLayer();
			featureLayer.FeatureClass = worldFeatureClass;
			// 设定符号
			IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)featureLayer;
			// 获取图层的渲染器然后设定其符号即可
			ISimpleRenderer simpleRender = (ISimpleRenderer)geoFeatureLayer.Renderer;
			simpleRender.Symbol = (ISymbol)fillSymbol;
			// 加入地图
			featureLayer.Name = "world_blue";
			mainMapControl.AddLayer(featureLayer);
			mainMapControl.Refresh();
			// 同步鹰眼数据
			SyncMapAndHawkeye();
		}

		/// <summary>
		/// 加入country图层并填充为diamond层
		/// </summary>
		private void addWorldAsDiamondLayerItem_Click(object sender, EventArgs e)
		{
			// 创建符号
			IMarkerFillSymbol markerSymbol = new MarkerFillSymbol();
			// 创建一个点符号用于装入MarkFillSymbol
			ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol();
			simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond;
			IRgbColor markerColor = new RgbColor();
			markerColor.Red = 254;
			markerColor.Green = 201;
			markerColor.Blue = 217;
			simpleMarkerSymbol.Color = markerColor;
			simpleMarkerSymbol.Size = 6;
			// 设定符号样式等等
			markerSymbol.Style = esriMarkerFillStyle.esriMFSGrid;
			// 装入符号至面填充符号
			markerSymbol.MarkerSymbol = simpleMarkerSymbol;
			// 使用工作区打开文件
			IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
			IWorkspace workspace = workspaceFactory.OpenFromFile(@"..\..\Resources\data", 0);
			IFeatureClass worldFeatureClass = ((IFeatureWorkspace)workspace).OpenFeatureClass("country");
			IFeatureLayer featureLayer = new FeatureLayer();
			featureLayer.FeatureClass = worldFeatureClass;
			// 设定符号
			IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)featureLayer;
			// 获取图层的渲染器然后设定其符号即可
			ISimpleRenderer simpleRender = (ISimpleRenderer)geoFeatureLayer.Renderer;
			simpleRender.Symbol = (ISymbol)markerSymbol;
			// 加入地图
			featureLayer.Name = "world_diamond";
			mainMapControl.AddLayer(featureLayer);
			mainMapControl.Refresh();
			// 同步鹰眼数据
			SyncMapAndHawkeye();
		}

		/// <summary>
		/// 加入country图层并按值渲染
		/// </summary>
		private void addCountryAndRenderValueItem_Click(object sender, EventArgs e)
		{
			// 使用工作区打开文件
			IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
			IWorkspace workspace = workspaceFactory.OpenFromFile(@"..\..\Resources\data", 0);
			IFeatureClass worldFeatureClass = ((IFeatureWorkspace)workspace).OpenFeatureClass("country");
			IFeatureLayer featureLayer = new FeatureLayer();
			featureLayer.FeatureClass = worldFeatureClass;
			string fieldName = "CNTRY_NAME";
			int fieldIndex = worldFeatureClass.FindField(fieldName);
			// 创建按值渲染器
			IUniqueValueRenderer uniqueRenderer = new UniqueValueRenderer();
			// 设定按值渲染的值的个数
			uniqueRenderer.FieldCount = 1;
			uniqueRenderer.Field[0] = fieldName;
			// 查找所有的值并加入到渲染器中
			IQueryFilter queryFilter = new QueryFilter();
			IFeatureCursor featureCursor = worldFeatureClass.Search(queryFilter, false);
			IFeature feature;
			while ((feature = featureCursor.NextFeature()) != null)
			{
				// 创建符号并设定其基本样式
				ISimpleMarkerSymbol markerSymbol = new SimpleMarkerSymbol();
				markerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond;
				markerSymbol.Size = 6;
				// 遍历每个要素的对应字段值
				string value = feature.get_Value(fieldIndex).ToString();
				// 检查渲染器里面是否已经有该国家的值了，如果有则不再重复添加对应的符号，否则就将该值加入渲染器中
				bool isValueFound = false;
				for (int i = 0; i < uniqueRenderer.ValueCount; i++)
				{
					if (uniqueRenderer.get_Value(i).ToString() == value)
					{
						isValueFound = true;
						break;
					}
				}
				if (!isValueFound)
				{
					uniqueRenderer.AddValue(value, "CNTRY_NAME", (ISymbol)markerSymbol);
					uniqueRenderer.set_Label(value, value);
					uniqueRenderer.set_Symbol(value, (ISymbol)markerSymbol);
				}
			}
			// 创建随机色带
			IRandomColorRamp colorRamp = new RandomColorRamp();
			colorRamp.MinSaturation = 20;
			colorRamp.MaxSaturation = 40;
			colorRamp.MinValue = 85;
			colorRamp.MaxValue = 100;
			colorRamp.StartHue = 76;
			colorRamp.EndHue = 188;
			colorRamp.UseSeed = true;
			colorRamp.Seed = uniqueRenderer.ValueCount + 5;
			colorRamp.Size = uniqueRenderer.ValueCount;
			bool bt = true;
			colorRamp.CreateRamp(out bt);
			IEnumColors enumColors = colorRamp.Colors;
			enumColors.Reset();
			// 遍历渲染器中每一个值，并将每个值设定为随机颜色
			for (int i = 0; i < uniqueRenderer.ValueCount; i++)
			{
				string value = uniqueRenderer.get_Value(i);
				ISimpleMarkerSymbol getSymbol = (ISimpleMarkerSymbol)uniqueRenderer.get_Symbol(value);
				getSymbol.Color = enumColors.Next();
				uniqueRenderer.set_Symbol(value, (ISymbol)getSymbol);
			}
			// 设定符号
			IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)featureLayer;
			// 获取图层的渲染器然后设定其符号即可
			geoFeatureLayer.Renderer = (IFeatureRenderer)uniqueRenderer;
			// 加入地图
			featureLayer.Name = "world_value";
			mainMapControl.AddLayer(featureLayer);
			mainMapControl.Refresh();
			// 同步鹰眼数据
			SyncMapAndHawkeye();
		}

		/// <summary>
		/// 将栅格进行重分类
		/// </summary>
		private void convertDEM_Click(object sender, EventArgs e)
		{
			IRasterLayer rasterLayer = (IRasterLayer)mainMapControl.get_Layer(0);
			IGeoDataset geoDataset = (IGeoDataset)rasterLayer;
			IMapAlgebraOp mapAlgebraOp = (IMapAlgebraOp)new RasterMapAlgebraOp();
			mapAlgebraOp.BindRaster(geoDataset, "dem");
			IGeoDataset outData = mapAlgebraOp.Execute("Con([dem] < 100, 1, Con([dem] < 200, 2, [dem]))");
			IRasterLayer resultRasterLayer = new RasterLayer();
			resultRasterLayer.Name = "dem-out";
			resultRasterLayer.CreateFromRaster((IRaster)outData);
			mainMapControl.AddLayer(resultRasterLayer);
		}

		/// <summary>
		/// 渲染C开头国家
		/// </summary>
		private void renderCStartCountryMenuItem_Click(object sender, EventArgs e)
		{
			// 使用工作区打开文件
			IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
			IWorkspace workspace = workspaceFactory.OpenFromFile(@"..\..\Resources\data", 0);
			IFeatureClass worldFeatureClass = ((IFeatureWorkspace)workspace).OpenFeatureClass("country");
			IFeatureLayer featureLayer = new FeatureLayer();
			featureLayer.FeatureClass = worldFeatureClass;
			string fieldName = "CNTRY_NAME";
			int fieldIndex = worldFeatureClass.FindField(fieldName);
			// 创建按值渲染器
			IUniqueValueRenderer uniqueRenderer = new UniqueValueRenderer();
			// 设定按值渲染的值的个数
			uniqueRenderer.FieldCount = 1;
			uniqueRenderer.Field[0] = fieldName;
			// 创建默认符号
			ISimpleFillSymbol defaultSymbol = new SimpleFillSymbol();
			defaultSymbol.Style = esriSimpleFillStyle.esriSFSHollow;
			uniqueRenderer.DefaultSymbol = (ISymbol)defaultSymbol;
			uniqueRenderer.UseDefaultSymbol = true;
			// 查找所有的值并加入到渲染器中
			IQueryFilter queryFilter = new QueryFilter();
			queryFilter.SubFields = "*";
			queryFilter.WhereClause = "CNTRY_NAME like \'C%\'";
			IFeatureCursor featureCursor = worldFeatureClass.Search(queryFilter, false);
			IFeature feature;
			while ((feature = featureCursor.NextFeature()) != null)
			{
				// 创建符号并设定其基本样式
				ISimpleFillSymbol eachFillSymbol = new SimpleFillSymbol();
				// 遍历每个要素的对应字段值
				string value = feature.get_Value(fieldIndex).ToString();
				// 检查渲染器里面是否已经有该国家的值了，如果有则不再重复添加对应的符号，否则就将该值加入渲染器中
				bool isValueFound = false;
				for (int i = 0; i < uniqueRenderer.ValueCount; i++)
				{
					if (uniqueRenderer.get_Value(i).ToString() == value)
					{
						isValueFound = true;
						break;
					}
				}
				if (!isValueFound)
				{
					uniqueRenderer.AddValue(value, "CNTRY_NAME", (ISymbol)eachFillSymbol);
					uniqueRenderer.set_Label(value, value);
					uniqueRenderer.set_Symbol(value, (ISymbol)eachFillSymbol);
				}
			}
			// 创建符号选择器
			ISymbologyControl symbologyControl = new SymbologyControlClass();
			// 加载符号库
			symbologyControl.LoadStyleFile(@"C:\Program Files (x86)\ArcGIS\Desktop10.2\Styles\ESRI.ServerStyle");
			// 获取其中随机色带
			ISymbologyStyleClass styleClass = symbologyControl.GetStyleClass(esriSymbologyStyleClass.esriStyleClassColorRamps);
			// 获取第56索引色带
			IStyleGalleryItem styleGallery = styleClass.GetItem(56);
			// 得到其中的色带
			IRandomColorRamp colorRamp = (IRandomColorRamp)styleGallery.Item;
			colorRamp.UseSeed = true;
			colorRamp.Seed = uniqueRenderer.ValueCount + 5;
			colorRamp.Size = uniqueRenderer.ValueCount;
			bool bt = true;
			colorRamp.CreateRamp(out bt);
			// 得到其中颜色
			IEnumColors enumColors = colorRamp.Colors;
			enumColors.Reset();
			// 遍历渲染器中每一个值，并将每个值设定为随机颜色
			for (int i = 0; i < uniqueRenderer.ValueCount; i++)
			{
				string value = uniqueRenderer.get_Value(i);
				ISimpleFillSymbol getSymbol = (ISimpleFillSymbol)uniqueRenderer.get_Symbol(value);
				getSymbol.Color = enumColors.Next();
				uniqueRenderer.set_Symbol(value, (ISymbol)getSymbol);
			}
			// 设定符号
			IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)featureLayer;
			// 获取图层的渲染器然后设定其符号即可
			geoFeatureLayer.Renderer = (IFeatureRenderer)uniqueRenderer;
			// 加入地图
			featureLayer.Name = "world_value";
			mainMapControl.AddLayer(featureLayer);
			mainMapControl.Refresh();
			// 同步鹰眼数据
			SyncMapAndHawkeye();
		}

		/// <summary>
		/// 按面积分类渲染
		/// </summary>
		private void areaRenderMenuItem_Click(object sender, EventArgs e)
		{
			// 使用工作区打开文件
			IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
			IWorkspace workspace = workspaceFactory.OpenFromFile(@"..\..\Resources\data", 0);
			IFeatureClass worldFeatureClass = ((IFeatureWorkspace)workspace).OpenFeatureClass("country");
			IFeatureLayer featureLayer = new FeatureLayer();
			featureLayer.FeatureClass = worldFeatureClass;
			// 获取图层属性表
			ITable countryTable = (ITable)worldFeatureClass;
			// 创建字段重分类并设定要重分类字段
			ITableHistogram tableHistogram = new BasicTableHistogramClass();
			IBasicHistogram histogram = (IBasicHistogram)tableHistogram;
			tableHistogram.Field = "SQKM";
			tableHistogram.Table = countryTable;
			object dataFrequency;
			object datavalues;
			histogram.GetHistogram(out datavalues, out dataFrequency);
			histogram.GetHistogram(out datavalues, out dataFrequency);
			IClassifyGEN classifyGEN = new Quantile();
			try
			{
				classifyGEN.Classify(datavalues, dataFrequency, 5);
			}
			catch (Exception)
			{
				return;
			}
			double[] classes = (double[])classifyGEN.ClassBreaks;
			// 重分类为5个
			IClassBreaksRenderer render = new ClassBreaksRenderer();
			render.Field = "SQKM";
			render.BreakCount = 5;
			render.MinimumBreak = classes[0];
			IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRamp();
			// 创建色带以及起始颜色和终止颜色
			colorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
			IRgbColor color1 = new RgbColor();
			IRgbColor color2 = new RgbColor();
			color1.Red = 255;
			color1.Green = 0;
			color1.Blue = 0;
			color2.Red = 0;
			color2.Green = 0;
			color2.Blue = 255;
			colorRamp.FromColor = color1;
			colorRamp.ToColor = color2;
			colorRamp.Size = 5;
			bool ok = false;
			colorRamp.CreateRamp(out ok);
			IEnumColors enumColors = colorRamp.Colors;
			enumColors.Reset();
			for (int i = 0; i < 5; i++)
			{
				render.set_Break(i, classes[i + 1]);
				render.set_Label(i, classes[i].ToString() + "-" + classes[i + 1].ToString());
				ISimpleFillSymbol simpleFillSym = new SimpleFillSymbol();
				simpleFillSym.Color = enumColors.Next();
				render.set_Symbol(i, (ISymbol)simpleFillSym);
			}
			((IGeoFeatureLayer)featureLayer).Renderer = (IFeatureRenderer)render;
			mainMapControl.AddLayer(featureLayer);
			mainMapControl.Refresh();
			SyncMapAndHawkeye();
		}

		/// <summary>
		/// 多色带重分类
		/// </summary>
		private void multipartColorRenderMenuItem_Click(object sender, EventArgs e)
		{
			// 使用工作区打开文件
			IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
			IWorkspace workspace = workspaceFactory.OpenFromFile(@"..\..\Resources\data", 0);
			IFeatureClass worldFeatureClass = ((IFeatureWorkspace)workspace).OpenFeatureClass("country");
			IFeatureLayer featureLayer = new FeatureLayer();
			featureLayer.FeatureClass = worldFeatureClass;
			// 获取图层属性表
			ITable countryTable = (ITable)worldFeatureClass;
			// 创建字段重分类并设定要重分类字段
			ITableHistogram tableHistogram = new BasicTableHistogramClass();
			IBasicHistogram histogram = (IBasicHistogram)tableHistogram;
			tableHistogram.Field = "SQKM";
			tableHistogram.Table = countryTable;
			object dataFrequency;
			object datavalues;
			histogram.GetHistogram(out datavalues, out dataFrequency);
			histogram.GetHistogram(out datavalues, out dataFrequency);
			IClassifyGEN classifyGEN = new Quantile();
			try
			{
				classifyGEN.Classify(datavalues, dataFrequency, 5);
			}
			catch (Exception)
			{
				return;
			}
			double[] classes = (double[])classifyGEN.ClassBreaks;
			// 重分类为5个
			IClassBreaksRenderer render = new ClassBreaksRenderer();
			render.Field = "SQKM";
			render.BreakCount = 5;
			render.MinimumBreak = classes[0];
			// 创建两个色带以及起始颜色和终止颜色
			IAlgorithmicColorRamp colorRamp1 = new AlgorithmicColorRamp();
			colorRamp1.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
			IRgbColor color1 = new RgbColor();
			IRgbColor color2 = new RgbColor();
			color1.Red = 255;
			color1.Green = 0;
			color1.Blue = 0;
			color2.Red = 0;
			color2.Green = 0;
			color2.Blue = 255;
			colorRamp1.FromColor = color1;
			colorRamp1.ToColor = color2;
			colorRamp1.Size = 5;
			IAlgorithmicColorRamp colorRamp2 = new AlgorithmicColorRamp();
			colorRamp2.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
			IRgbColor color3 = new RgbColor();
			IRgbColor color4 = new RgbColor();
			color3.Red = 255;
			color3.Green = 255;
			color3.Blue = 128;
			color4.Red = 242;
			color4.Green = 167;
			color4.Blue = 46;
			colorRamp2.FromColor = color3;
			colorRamp2.ToColor = color4;
			colorRamp2.Size = 5;
			IMultiPartColorRamp multiPartColorRamp = new MultiPartColorRamp();
			multiPartColorRamp.AddRamp(colorRamp1);
			multiPartColorRamp.AddRamp(colorRamp2);
			multiPartColorRamp.Size = 5;
			bool ok = false;
			multiPartColorRamp.CreateRamp(out ok);
			IEnumColors enumColors = multiPartColorRamp.Colors;
			enumColors.Reset();
			for (int i = 0; i < 5; i++)
			{
				render.set_Break(i, classes[i + 1]);
				render.set_Label(i, classes[i].ToString() + "-" + classes[i + 1].ToString());
				ISimpleFillSymbol simpleFillSym = new SimpleFillSymbol();
				simpleFillSym.Color = enumColors.Next();
				render.set_Symbol(i, (ISymbol)simpleFillSym);
			}
			((IGeoFeatureLayer)featureLayer).Renderer = (IFeatureRenderer)render;
			mainMapControl.AddLayer(featureLayer);
			mainMapControl.Refresh();
			SyncMapAndHawkeye();
		}

		/// <summary>
		/// 指定分级断点渲染
		/// </summary>
		private void specificValueRenderMenuItem_Click(object sender, EventArgs e)
		{
			// 使用工作区打开文件
			IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
			IWorkspace workspace = workspaceFactory.OpenFromFile(@"..\..\Resources\data", 0);
			IFeatureClass worldFeatureClass = ((IFeatureWorkspace)workspace).OpenFeatureClass("country");
			IFeatureLayer featureLayer = new FeatureLayer();
			featureLayer.FeatureClass = worldFeatureClass;
			// 获取图层属性表
			ITable countryTable = (ITable)worldFeatureClass;
			// 创建字段重分类并设定要重分类字段
			ITableHistogram tableHistogram = new BasicTableHistogramClass();
			tableHistogram.Field = "SQKM";
			tableHistogram.Table = countryTable;
			// 指定断点
			double[] classes = { 210000, 750000, 1650000, 3000000, 16897294 };
			// 重分类为5个
			IClassBreaksRenderer render = new ClassBreaksRenderer();
			render.Field = "SQKM";
			render.BreakCount = 5;
			render.MinimumBreak = classes[0];
			IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRamp();
			// 创建色带以及起始颜色和终止颜色
			colorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
			IRgbColor color1 = new RgbColor();
			IRgbColor color2 = new RgbColor();
			color1.Red = 255;
			color1.Green = 0;
			color1.Blue = 0;
			color2.Red = 0;
			color2.Green = 0;
			color2.Blue = 255;
			colorRamp.FromColor = color1;
			colorRamp.ToColor = color2;
			colorRamp.Size = 5;
			bool ok = false;
			colorRamp.CreateRamp(out ok);
			IEnumColors enumColors = colorRamp.Colors;
			enumColors.Reset();
			for (int i = 0; i < classes.Length - 1; i++)
			{
				render.set_Break(i, classes[i + 1]);
				render.set_Label(i, classes[i].ToString() + "-" + classes[i + 1].ToString());
				ISimpleFillSymbol simpleFillSym = new SimpleFillSymbol();
				simpleFillSym.Color = enumColors.Next();
				render.set_Symbol(i, (ISymbol)simpleFillSym);
			}
			((IGeoFeatureLayer)featureLayer).Renderer = (IFeatureRenderer)render;
			mainMapControl.AddLayer(featureLayer);
			mainMapControl.Refresh();
			SyncMapAndHawkeye();
		}

		/// <summary>
		/// 显示点密度
		/// </summary>
		private void denMenuItem_Click(object sender, EventArgs e)
		{
			// 使用工作区打开文件
			IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
			IWorkspace workspace = workspaceFactory.OpenFromFile(@"..\..\Resources\data", 0);
			IFeatureClass worldFeatureClass = ((IFeatureWorkspace)workspace).OpenFeatureClass("country");
			IFeatureLayer featureLayer = new FeatureLayer();
			featureLayer.FeatureClass = worldFeatureClass;
			IDotDensityRenderer render = new DotDensityRendererClass();
			render.DotValue = 100000;
			IRendererFields fields = (IRendererFields)render;
			fields.AddField("SQKM");
			ISimpleMarkerSymbol markerSymbol = new SimpleMarkerSymbol();
			markerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
			IDotDensityFillSymbol densityFillSymbol = new DotDensityFillSymbol();
			densityFillSymbol.DotSize = 3;
			((ISymbolArray)densityFillSymbol).AddSymbol((ISymbol)markerSymbol);
			render.DotDensitySymbol = densityFillSymbol;
			render.CreateLegend();
			((IGeoFeatureLayer)featureLayer).Renderer = (IFeatureRenderer)render;
			mainMapControl.AddLayer(featureLayer);
			mainMapControl.Refresh();
			SyncMapAndHawkeye();
		}

		/// <summary>
		/// 显示城市名和国家名1
		/// </summary>
		private void showCityNameMenuItem_Click(object sender, EventArgs e)
		{
			// 使用工作区打开文件
			IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
			IWorkspace workspace = workspaceFactory.OpenFromFile(@"..\..\Resources\data", 0);
			IFeatureClass citiesFeatureClass = ((IFeatureWorkspace)workspace).OpenFeatureClass("cities");
			IFeatureLayer featureLayer = new FeatureLayer();
			featureLayer.FeatureClass = citiesFeatureClass;
			IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)featureLayer;
			IAnnotateLayerPropertiesCollection propertiesCollection = geoFeatureLayer.AnnotationProperties;
			propertiesCollection.Clear();
			// 创建图层属性引擎并设定表达式
			ILabelEngineLayerProperties layerProperties = new LabelEngineLayerPropertiesClass();
			layerProperties.Expression = "[CITY_NAME] &vbCrlf& [CNTRY_NAME]";
			// 定义文字符号样式
			ITextSymbol textSymbol = layerProperties.Symbol;
			textSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter;
			textSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter;
			textSymbol.Size = 9;
			textSymbol.Font.Name = "宋体";
			// 设定显示位置参数
			IPointPlacementPriorities placementPriorities = new PointPlacementPriorities();
			placementPriorities.AboveCenter = 1;
			placementPriorities.AboveRight = 0;
			layerProperties.BasicOverposterLayerProperties.PointPlacementPriorities = placementPriorities;
			// 开启图层文字标记显示
			geoFeatureLayer.DisplayAnnotation = true;
			propertiesCollection.Add((IAnnotateLayerProperties)layerProperties);
			mainMapControl.AddLayer(featureLayer);
			mainMapControl.Refresh();
			SyncMapAndHawkeye();
		}

		/// <summary>
		/// 显示城市名和国家名2
		/// </summary>
		private void showCityAndCountryMenuItem_Click(object sender, EventArgs e)
		{
			// 使用工作区打开文件
			IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
			IWorkspace workspace = workspaceFactory.OpenFromFile(@"..\..\Resources\data", 0);
			IFeatureClass citiesFeatureClass = ((IFeatureWorkspace)workspace).OpenFeatureClass("cities");
			IFeatureLayer featureLayer = new FeatureLayer();
			featureLayer.FeatureClass = citiesFeatureClass;
			IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)featureLayer;
			// 创建注解集
			IAnnotateLayerPropertiesCollection propertiesCollection = geoFeatureLayer.AnnotationProperties;
			propertiesCollection.Clear();
			// 创建图层城市名属性引擎并设定表达式
			ILabelEngineLayerProperties cityLayerProperties = new LabelEngineLayerPropertiesClass();
			cityLayerProperties.Expression = "[CITY_NAME]";
			// 定义文字符号样式
			ITextSymbol cityTextSymbol = cityLayerProperties.Symbol;
			cityTextSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter;
			cityTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter;
			cityTextSymbol.Size = 9;
			cityTextSymbol.Font.Name = "宋体";
			// 设定显示位置参数
			IPointPlacementPriorities cityTextplacementPriorities = new PointPlacementPriorities();
			cityTextplacementPriorities.AboveCenter = 1;
			cityTextplacementPriorities.AboveRight = 0;
			cityLayerProperties.BasicOverposterLayerProperties.PointPlacementPriorities = cityTextplacementPriorities;
			// 创建图层国家名属性引擎并设定表达式
			ILabelEngineLayerProperties countryLayerProperties = new LabelEngineLayerPropertiesClass();
			countryLayerProperties.Expression = "[CNTRY_NAME]";
			// 定义文字符号样式
			ITextSymbol countryTextSymbol = countryLayerProperties.Symbol;
			countryTextSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter;
			countryTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter;
			countryTextSymbol.Size = 9;
			countryTextSymbol.Font.Name = "宋体";
			// 设定显示位置参数
			IPointPlacementPriorities countryTextplacementPriorities = new PointPlacementPriorities();
			countryTextplacementPriorities.BelowCenter = 1;
			countryTextplacementPriorities.AboveRight = 0;
			countryLayerProperties.BasicOverposterLayerProperties.PointPlacementPriorities = countryTextplacementPriorities;
			// 开启图层文字标记显示
			geoFeatureLayer.DisplayAnnotation = true;
			// 加入属性集
			propertiesCollection.Add((IAnnotateLayerProperties)cityLayerProperties);
			propertiesCollection.Add((IAnnotateLayerProperties)countryLayerProperties);
			mainMapControl.AddLayer(featureLayer);
			mainMapControl.Refresh();
			SyncMapAndHawkeye();
		}

		/// <summary>
		/// 标注中国的城市
		/// </summary>
		private void showChinaCitiesMenuItem_Click(object sender, EventArgs e)
		{
			// 使用工作区打开文件
			IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
			IWorkspace workspace = workspaceFactory.OpenFromFile(@"..\..\Resources\data", 0);
			IFeatureClass citiesFeatureClass = ((IFeatureWorkspace)workspace).OpenFeatureClass("cities");
			IFeatureLayer featureLayer = new FeatureLayer();
			featureLayer.FeatureClass = citiesFeatureClass;
			IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)featureLayer;
			IAnnotateLayerPropertiesCollection propertiesCollection = geoFeatureLayer.AnnotationProperties;
			propertiesCollection.Clear();
			// 创建图层属性引擎并设定表达式
			ILabelEngineLayerProperties layerProperties = new LabelEngineLayerPropertiesClass();
			layerProperties.IsExpressionSimple = false;
			layerProperties.ExpressionParser = new AnnotationVBScriptEngine();
			layerProperties.Expression = "Function FindLabel ( [CITY_NAME] , [CNTRY_NAME] ) if ( [CNTRY_NAME] = \"China\") then FindLabel = [CITY_NAME] end if End Function";
			// 定义文字符号样式
			ITextSymbol textSymbol = layerProperties.Symbol;
			textSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter;
			textSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter;
			textSymbol.Size = 9;
			textSymbol.Font.Name = "宋体";
			// 设定显示位置参数
			IPointPlacementPriorities placementPriorities = new PointPlacementPriorities();
			placementPriorities.AboveCenter = 1;
			placementPriorities.AboveRight = 0;
			layerProperties.BasicOverposterLayerProperties.PointPlacementPriorities = placementPriorities;
			// 开启图层文字标记显示
			geoFeatureLayer.DisplayAnnotation = true;
			// 如果不用复杂表达式，还可以如下写↓
			// ((IAnnotateLayerProperties)layerProperties).WhereClause = "CNTRY_NAME = \'China\'";
			propertiesCollection.Add((IAnnotateLayerProperties)layerProperties);
			mainMapControl.AddLayer(featureLayer);
			mainMapControl.Refresh();
			SyncMapAndHawkeye();
		}

		/// <summary>
		/// 显示国家图层tip
		/// </summary>
		private void showCountryTipsMenuItem_Click(object sender, EventArgs e)
		{
			// 使用工作区打开文件
			IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
			IWorkspace workspace = workspaceFactory.OpenFromFile(@"..\..\Resources\data", 0);
			IFeatureClass worldFeatureClass = ((IFeatureWorkspace)workspace).OpenFeatureClass("country");
			IFeatureLayer featureLayer = new FeatureLayer();
			featureLayer.FeatureClass = worldFeatureClass;
			// 设定显示提示的字段名
			featureLayer.DisplayField = "CNTRY_NAME";
			// 打开提示
			featureLayer.ShowTips = true;
			mainMapControl.ShowMapTips = true;
			mainMapControl.AddLayer(featureLayer);
			mainMapControl.Refresh();
			SyncMapAndHawkeye();
		}

		/// <summary>
		/// 加入国家图层
		/// </summary>
		private void addDataMenuItem_Click(object sender, EventArgs e)
		{
			IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
			IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(@"E:\中转\世界地图", 0);
			IFeatureClass featureClass = featureWorkspace.OpenFeatureClass("country");
			IFeatureLayer featureLayer = new FeatureLayer();
			featureLayer.FeatureClass = featureClass;
			mainMapControl.AddLayer(featureLayer);
			mainMapControl.Refresh();
			SyncMapAndHawkeye();
		}

		/// <summary>
		/// 删除一个要素
		/// </summary>
		private void deleteFeatureMenuItem_Click(object sender, EventArgs e)
		{
			// 获取第一个图层为当前工作区
			IFeatureLayer featureLayer = (FeatureLayer)mainMapControl.get_Layer(0);
			IFeatureClass featureClass = featureLayer.FeatureClass;
			IDataset dataset = (IDataset)featureClass;
			IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)dataset.Workspace;
			workspaceEdit.StartEditing(true);
			workspaceEdit.StartEditOperation();
			IFeature feature = featureClass.GetFeature(233);
			feature.Delete();
			mainMapControl.Refresh();
			workspaceEdit.StopEditOperation();
			if (MessageBox.Show("undo operation", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
			{
				workspaceEdit.UndoEditOperation();
			}
			bool be = true;
			workspaceEdit.HasEdits(ref be);
			if (be)
			{
				if (MessageBox.Show("Save edits", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
				{
					workspaceEdit.StopEditing(true);
				}
				else
				{
					workspaceEdit.StopEditing(false);
				}
			}
			mainMapControl.Refresh();
		}

		/// <summary>
		/// 创建点图层
		/// </summary>
		private void createPointMenuItem_Click(object sender, EventArgs e)
		{
			// 创建字段集
			IFields fields = new FieldsClass();
			IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
			// 创建oid字段
			IField field = new FieldClass();
			IFieldEdit fieldEdit = (IFieldEdit)field;
			fieldEdit.Name_2 = "OID";
			fieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
			fieldsEdit.AddField(field);
			// 定义图层类型
			IGeometryDef geometryDef = new GeometryDefClass();
			IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
			geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
			// 创建Shape字段
			field = new FieldClass();
			IFieldEdit geometryFieldEdit = (IFieldEdit)field;
			geometryFieldEdit.Name_2 = "Shape";
			geometryFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
			geometryFieldEdit.GeometryDef_2 = geometryDef;
			fieldsEdit.AddField(field);
			// 创建名字字段
			field = new FieldClass();
			IFieldEdit nameFieldEdit = (IFieldEdit)field;
			nameFieldEdit.Name_2 = "Name";
			nameFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
			nameFieldEdit.Length_2 = 20;
			fieldsEdit.AddField(field);
			IFieldChecker fieldChecker = new FieldCheckerClass();
			IEnumFieldError enumFieldError = null;
			IFields validatedFields = null;
			IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
			IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(@"E:\中转\世界地图", 0);
			fieldChecker.ValidateWorkspace = (IWorkspace)featureWorkspace;
			fieldChecker.Validate(fields, out enumFieldError, out validatedFields);
			IFeatureClass featureClass = featureWorkspace.CreateFeatureClass("点图层", validatedFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
			IFeatureLayer featureLayer = new FeatureLayer();
			featureLayer.Name = "绘制点层";
			featureLayer.FeatureClass = featureClass;
			IWorkspaceEdit edit = (IWorkspaceEdit)featureWorkspace;
			edit.StartEditing(true);
			edit.StartEditOperation();
			IFeature feature = featureClass.CreateFeature();
			IGeometry geometry = new PointClass();
			((IPoint)geometry).PutCoords(100, 100);
			feature.Shape = geometry;
			int index = fields.FindField("Name");
			feature.set_Value(index, "test");
			feature.Store();
			edit.StopEditOperation();
			edit.StopEditing(true);
			mainMapControl.AddLayer(featureLayer);
			mainMapControl.Refresh();
			SyncMapAndHawkeye();
		}

		/// <summary>
		/// 把相交部分复制为新图层
		/// </summary>
		private void copyIntersectMenuItem_Click(object sender, EventArgs e)
		{
			// 获取第一个图层为当前工作区
			IFeatureLayer featureLayer = (FeatureLayer)mainMapControl.get_Layer(0);
			IFeatureClass featureClass = featureLayer.FeatureClass;
			IDataset dataset = (IDataset)featureClass;
			IFeatureWorkspace workspace = (IFeatureWorkspace)dataset.Workspace;
			IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace;
			workspaceEdit.StartEditing(true);
			workspaceEdit.StartEditOperation();
			// 把原图层字段照抄到新图层字段
			IFields fields = new FieldsClass();
			IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
			for (int i = 0; i < featureClass.Fields.FieldCount; i++)
			{
				fieldsEdit.AddField(featureClass.Fields.Field[i]);
			}
			IFeatureClass newFeatureClass = workspace.CreateFeatureClass("图层", fields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
			IFeatureLayer newFeatureLayer = new FeatureLayer();
			newFeatureLayer.Name = "复制裁剪图层";
			newFeatureLayer.FeatureClass = newFeatureClass;
			CopyIntersect copyIntersect = new CopyIntersect(newFeatureLayer);
			copyIntersect.OnCreate(mainMapControl);
			mainMapControl.CurrentTool = copyIntersect;
			workspaceEdit.StopEditing(true);
			mainMapControl.AddLayer(newFeatureLayer);
		}

		/// <summary>
		/// 获取第一个栅格图层通道最大最小值和格距
		/// </summary>
		private void getFirstRasterMinMax_Click(object sender, EventArgs e)
		{
			IRasterLayer rasterLayer = (IRasterLayer)mainMapControl.get_Layer(0);
			IRaster raster = rasterLayer.Raster;
			IRasterBandCollection rasterCollection = (IRasterBandCollection)raster;
			string result = "";
			for (int i = 0; i < rasterCollection.Count; i++)
			{
				IRasterBand rasterBand = rasterCollection.Item(i);
				bool hasStatistics;
				rasterBand.HasStatistics(out hasStatistics);
				if (!hasStatistics)
				{
					rasterBand.ComputeStatsAndHist();
				}
				string max = rasterBand.Statistics.Maximum.ToString();
				string min = rasterBand.Statistics.Minimum.ToString();
				result += "通道：" + rasterBand.Bandname + " 最大：" + max + " 最小：" + min + "\r\n";
			}
			// 获取格距
			IRasterProps rasterProps = (IRasterProps)raster;
			result += "格距X：" + rasterProps.MeanCellSize().X + " 格距Y：" + rasterProps.MeanCellSize().Y + " 行：" + rasterProps.Height + "列：" + rasterProps.Width;
			MessageBox.Show(result, "结果", MessageBoxButtons.OK, MessageBoxIcon.Information);
		}

		/// <summary>
		/// IDW插值
		/// </summary>
		private void iDWToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (mainMapControl.LayerCount == 0)
			{
				MessageBox.Show("请至少加入一个图层！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
				return;
			}
			IDWDialog dialog = new IDWDialog(mainMapControl);
			if (dialog.ShowDialog() == DialogResult.OK)
			{
				IFeatureClass featureClass = dialog.FeatureLayer.FeatureClass;
				// 创建要素类描述符，设定输入图层和字段
				IFeatureClassDescriptor descriptor = new FeatureClassDescriptorClass();
				descriptor.Create(featureClass, null, dialog.Field);
				IGeoDataset inputDataset = (IGeoDataset)descriptor;
				// 设定搜索半径
				IRasterRadius radius = new RasterRadius();
				radius.SetVariable(12);
				// 栅格分析器
				IInterpolationOp interpolationOp = new RasterInterpolationOpClass();
				IRasterAnalysisEnvironment rasterAnalysis = (IRasterAnalysisEnvironment)interpolationOp;
				// 设定格距
				rasterAnalysis.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, 0.5);
				// 创建工作区设定输出路径
				IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactory();
				rasterAnalysis.OutWorkspace = workspaceFactory.OpenFromFile(dialog.OutputPathString, 0);
				// 执行IDW插值
				IGeoDataset outputDataset = interpolationOp.IDW(inputDataset, 2, radius);
				// 得到插值
				IRasterLayer rasterLayer = new RasterLayer();
				rasterLayer.Name = dialog.FeatureLayer.Name + "_IDW";
				rasterLayer.CreateFromRaster((IRaster)outputDataset);
				mainMapControl.AddLayer(rasterLayer);
			}
		}

		/// <summary>
		/// 把画的区域变为0
		/// </summary>
		private void drawPolygonToZero_Click(object sender, EventArgs e)
		{
			SelectToZero selectToZero = new SelectToZero();
			selectToZero.OnCreate(mainMapControl);
			mainMapControl.CurrentTool = selectToZero;
		}

		/// <summary>
		/// 保存为tif
		/// </summary>
		private void saveAsTifMenuItem_Click(object sender, EventArgs e)
		{
			IRasterLayer rasterLayer = (IRasterLayer)mainMapControl.get_Layer(0);
			IRaster raster = rasterLayer.Raster;
			IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactory();
			SaveFileDialog dialog = new SaveFileDialog();
			dialog.Filter = "tif图像|*.tif";
			if (dialog.ShowDialog() == DialogResult.OK)
			{
				string filePath = dialog.FileName;
				IWorkspace workspace = workspaceFactory.OpenFromFile(filePath.Substring(0, filePath.LastIndexOf("\\")), 0);
				((ISaveAs)raster).SaveAs(filePath.Substring(filePath.LastIndexOf("\\") + 1), workspace, "TIFF");
			}
		}

		/// <summary>
		/// 等值线
		/// </summary>
		private void sameValueMenuItem_Click(object sender, EventArgs e)
		{
			IGeoDataset inputDataset = (IGeoDataset)mainMapControl.get_Layer(0);
			ISurfaceOp surfaceOp = new RasterSurfaceOpClass();
			double[] array = { 1, 3, 4, 5 };
			IGeoDataset dataset = surfaceOp.Contour(inputDataset, 100, 0);
			IFeatureClass featureClass = (IFeatureClass)surfaceOp.ContourList(dataset, array);
			IFeatureLayer featureLayer = new FeatureLayer();
			featureLayer.Name = "等值线";
			featureLayer.FeatureClass = featureClass;
			mainMapControl.AddLayer(featureLayer);
			mainMapControl.Refresh();
		}

		/// <summary>
		/// 以苏丹为形状裁切栅格
		/// </summary>
		private void getSudanPolygonToRasterMenuItem_Click(object sender, EventArgs e)
		{
			IFeatureLayer featureLayer = (IFeatureLayer)mainMapControl.get_Layer(0);
			IQueryFilter filter = new QueryFilter();
			filter.SubFields = "*";
			filter.WhereClause = "CNTRY_NAME = \'Sudan\'";
			IFeatureCursor cursor = featureLayer.Search(filter, false);
			IFeature feature;
			IRasterLayer rasterLayer = (IRasterLayer)mainMapControl.get_Layer(1);
			IRaster raster = rasterLayer.Raster;
			while ((feature = cursor.NextFeature()) != null)
			{
				IGeometry geometry = feature.Shape;
				IExtractionOp extraction = new RasterExtractionOpClass();
				IGeoDataset dataset = extraction.Polygon((IGeoDataset)raster, (IPolygon)geometry, false);
				IRasterLayer rasterLayer1 = new RasterLayer();
				rasterLayer1.CreateFromRaster((IRaster)dataset);
				mainMapControl.AddLayer(rasterLayer1);
				mainMapControl.Refresh();
			}
		}

		/// <summary>
		/// 把栅格值乘2
		/// </summary>
		private void doubleRasterMenuItem_Click(object sender, EventArgs e)
		{
			IRasterLayer rasterLayer = (IRasterLayer)mainMapControl.get_Layer(0);
			IGeoDataset geoDataset = (IGeoDataset)rasterLayer;
			IMapAlgebraOp mapAlgebraOp = (IMapAlgebraOp)new RasterMapAlgebraOp();
			mapAlgebraOp.BindRaster(geoDataset, "raster");
			IGeoDataset outData = mapAlgebraOp.Execute("[raster] * 2");
			IRasterLayer resultRasterLayer = new RasterLayer();
			resultRasterLayer.Name = "raster-double";
			resultRasterLayer.CreateFromRaster((IRaster)outData);
			mainMapControl.AddLayer(resultRasterLayer);
		}

		/// <summary>
		/// 重分类栅格
		/// </summary>
		private void rasterReclassMenuItem_Click(object sender, EventArgs e)
		{
			IRasterLayer rasterLayer = (IRasterLayer)mainMapControl.get_Layer(0);
			IGeoDataset geoDataset = (IGeoDataset)rasterLayer;
			IMapAlgebraOp mapAlgebraOp = (IMapAlgebraOp)new RasterMapAlgebraOp();
			mapAlgebraOp.BindRaster(geoDataset, "raster");
			IGeoDataset outData = mapAlgebraOp.Execute("Con([raster] > 4, [raster], Con([raster] > 2, 2, 1))");
			IRasterLayer resultRasterLayer = new RasterLayer();
			resultRasterLayer.Name = "raster-reclass";
			resultRasterLayer.CreateFromRaster((IRaster)outData);
			mainMapControl.AddLayer(resultRasterLayer);
		}

		/// <summary>
		/// 拉伸渲染
		/// </summary>
		private void stretchRenderMenuItem_Click(object sender, EventArgs e)
		{
			// 设定起始颜色和终止颜色
			IRgbColor fromColor = new RgbColorClass();
			fromColor.Red = 255;
			fromColor.Green = 0;
			fromColor.Blue = 0;
			IColor toColor = new RgbColorClass();
			fromColor.Red = 0;
			fromColor.Green = 255;
			fromColor.Blue = 0;
			// 创建算法色带
			IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRampClass();
			colorRamp.Size = 255;
			colorRamp.FromColor = fromColor;
			colorRamp.ToColor = toColor;
			bool createColorRamp;
			colorRamp.CreateRamp(out createColorRamp);
			// 拉伸渲染器
			IRasterStretchColorRampRenderer stretchRenderer = new RasterStretchColorRampRendererClass();
			IRasterRenderer rasterRenderer = (IRasterRenderer)stretchRenderer;
			// 获取图层为栅格数据集
			IRasterLayer rasterLayer = (IRasterLayer)mainMapControl.get_Layer(0);
			IRaster raster = rasterLayer.Raster;
			rasterRenderer.Raster = raster;
			rasterRenderer.Update();
			stretchRenderer.BandIndex = 0;
			stretchRenderer.ColorRamp = colorRamp;
			// 设定拉伸系数
			IRasterStretch stretchType = (IRasterStretch)rasterRenderer;
			stretchType.StretchType = esriRasterStretchTypesEnum.esriRasterStretch_StandardDeviations;
			stretchType.StandardDeviationsParam = 2;
			rasterLayer.Renderer = rasterRenderer;
			mainMapControl.Refresh();
		}

		/// <summary>
		/// 自然断点法重分类渲染
		/// </summary>
		private void natureBreakMenuItem_Click(object sender, EventArgs e)
		{
			IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass();
			IWorkspace workspace = workspaceFactory.OpenFromFile(@"F:\ArcGIS\测试输出", 0);
			IRasterWorkspace rasterWorkspace = (IRasterWorkspace)workspace;
			IRaster raster = rasterWorkspace.OpenRasterDataset("pop.tif").CreateDefaultRaster();
			IRasterClassifyColorRampRenderer classifyColorRampRenderer = new RasterClassifyColorRampRenderer();
			IRasterRenderer rasterRenderer = (IRasterRenderer)classifyColorRampRenderer;
			rasterRenderer.Raster = raster;
			classifyColorRampRenderer.ClassCount = 5;
			IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRamp();
			colorRamp.Size = 5;
			bool bt = true;
			colorRamp.CreateRamp(out bt);
			for (int i = 0; i < 5; i++)
			{
				IFillSymbol fillSymbol = new SimpleFillSymbol();
				fillSymbol.Color = colorRamp.get_Color(i);
				classifyColorRampRenderer.set_Symbol(i, (ISymbol)fillSymbol);
				classifyColorRampRenderer.set_Label(i, "分级_" + i.ToString());
			}
			IRasterLayer rasterLayer = new RasterLayer();
			rasterLayer.Renderer = rasterRenderer;
			rasterLayer.CreateFromRaster(raster);
			mainMapControl.AddLayer(rasterLayer);
			mainMapControl.Refresh();
		}
	}
}